//============================================================================
// Name        : ass2.cpp
// Author      : leveh
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<string>
#include <iostream>

#include <stdio.h>
#include <stdlib.h>

#include "SystemCall.h"



#define NO_ERROR 0

#include <fstream>


using namespace std;

static int numberOfInodes=120;
static int diskSize= 200;
static int blockSize=64;

void sprintb(char *s, unsigned n) {
     unsigned mask = ~(~0u >> 1);

     while (mask) {
         *s++ = n & mask ? '1' : '0';
         mask >>= 1;
     }
     *s = '\0';
 }

void test1(){
	int size=0;
	MyDisk *ptr;
	ptr=new MyDisk();
	ptr->init(100);

	string blabla = "test number 1";
	size=blabla.size();
	ptr->writeChar((char*)blabla.c_str(),5,size);
	char* ans=(char*)malloc(size);
	ptr->readChar(ans,5,size);
	printf("%s\n",ans);
	free(ans);
	delete(ptr);

}

void test2(){
	int x=35564039;
	int y;
	MyDisk *ptr;
	ptr=new MyDisk();
	ptr->init(100);
	ptr->writeInt(x,0);
	y = ptr->readInt(0);

	printf("test2 35564039 == %d\n",y);
	delete(ptr);

}

void test3(){
	int size;
	int x=3;
	int y;
	MyDisk *ptr;
	ptr=new MyDisk();
	ptr->init(100);
	//writing number
	ptr->writeInt(x,0);
	//writing string
	string blabla = "test number";
	size=blabla.size();
	ptr->writeChar((char*)blabla.c_str(),4,size);


	//reading number
	y = ptr->readInt(0);
	//reading string
	char* ans=(char*)malloc(size);
	ptr->readChar(ans,4,size);
	//print string
	printf("%s ",ans);
	//print number
	printf("%d\n",y);
	delete(ptr);
	free(ans);

}

void test4(){
	MyDisk *ptr;
	ptr=new MyDisk(1,2,6,true);
	ptr->SB.printMe();
}
//should use only if after init disk because of false PLEASE DO TEST 4 WITH THIS
void test5(){
	MyDisk *ptr;
	int size=100;
	ptr=new MyDisk(size,64,36,false);
	ptr->SB.printMe();
	for (int i=0;i<size;i++){
		printf("the %d block is in offset %d\n",i,ptr->getBlockOffset(i));
	}
	delete(ptr);
}
/**
 * testing reading and wrinting to a specific block
 *
 */
void test6(){
	MyDisk *ptr;
	int dblock=5;
	int size=100;
	int block=64;
	char* buf=(char*)malloc(block);
	string test6="test 6 writng and reading blocks";
	ptr=new MyDisk(size,64,36,true);
	ptr->SB.printMe();
	ptr->writeBlock(dblock , (char*)test6.c_str());
	ptr->readBlock(dblock,buf);
	printf("%s\n",buf);
	free(buf);
	delete(ptr);
}
/*
void test7(){
	MyDisk *ptr;
	ptr=new MyDisk(500,64,36,true);
	////
	ptr->initFreeList();
	ptr->SB.printMe();
	ptr->printFList();

	////
	delete(ptr);
}
*/
void test8(){
	MyDisk *ptr;
	ptr=new MyDisk(100,64,36,true);
	////
//	ptr->initFreeList();
	ptr->SB.printMe();
	ptr->printFList();
	for (int i = 0 ; i < 100 ; i++  )
		printf ("allocate block is %d\n",ptr->allocateDataBlock());

	////
	delete(ptr);
}


void test9(){
	MyDisk *ptr;
	ptr=new MyDisk(100,64,36,true);
	////
//	ptr->initFreeList();
	ptr->SB.printMe();
	ptr->printFList();
	int *arr=new int[10];
	for (int i=0;i<10;i++){
		arr[i]=ptr->allocateDataBlock();
		printf ("allocate block is %d\n",arr[i]);
	}
	for (int i = 0 ;  i < 10 ; i++){
		if (!ptr->isFreeBlock(arr[i])){
			printf ("%d block is not free\n",arr[i]);
			printf ("free the block and the offset is %d\n",ptr->freeDataBlock(arr[i]));

		}
	}
	ptr->printFList();

	////
	delete(ptr);
}

//testing size of free list
void test10(){
	MyDisk *ptr;
	ptr=new MyDisk(100,64,36,true);
	////
//	ptr->initFreeList();
	ptr->SB.printMe();
	ptr->printFList();
	int *arr=new int[50];
	printf("the size before allocating is %d\n",ptr->freeListSize);
	for (int i=0;i<50;i++){
		arr[i]=ptr->allocateDataBlock();
		printf ("allocate block is %d\n",arr[i]);
	}
	printf("the size after 50 allocating is %d\n",ptr->freeListSize);


	////
	delete(ptr);
}

//testing print super block
void test11(){
	MyDisk *ptr;
	ptr=new MyDisk(100,64,30,true);
	ptr->printSuperBlock();
//	ptr->printFList();
	////
	delete(ptr);
}


//testing array of iNode
void test12(){
	MyDisk *ptr;
	int blockSize=64;
	int numOfNodes=30;
	ptr=new MyDisk(100,blockSize,numOfNodes,true);
	ptr->printSuperBlock();
//	ptr->printFList();
	for (int i=0;i<numOfNodes;i++){
		printf("Inode %d is in ref = %d, block = %d\n",i,ptr->getInode(i),
				ptr->getInode(i)/blockSize);
	}
	ptr->printFList();
	////
	delete(ptr);
}



//testing array of iNode
void test13(){
	MyDisk *ptr;
	int blockSize=64;
	int numOfNodes=10;
	ptr=new MyDisk(200,blockSize,numOfNodes,true);
	ptr->printSuperBlock();

	for (int i=0;i<numOfNodes;i++){
			printf("Inode %d is in ref = %d, block = %d\n",i,ptr->getInode(i),
			ptr->getInode(i)/blockSize);
	}
	ptr->printFreeInodeList();
	ptr->printFList();
	////
	delete(ptr);
}

//testing array of iNode
//testing allocate
void test14(){
	MyDisk *ptr;
	int blockSize=64;
	int numOfNodes=120;
	ptr=new MyDisk(200,blockSize,numOfNodes,true);
	ptr->printSuperBlock();
	ptr->printFreeInodeList();

	int inode=0;
	for (int i=0 ; i < 57; i++){
		inode=ptr->allocateInode();
		printf("allocate the indoe %d ref == %d\n",inode,ptr->getInode(inode));
	}
	ptr->printFreeInodeList();

//	ptr->printFList();
	////
	delete(ptr);
}


//testing array of iNode
//testing allocate
//testing isfree inode
void test15(){
	MyDisk *ptr;
	int blockSize=64;
	int numOfNodes=25;
	ptr=new MyDisk(200,blockSize,numOfNodes,true);
	ptr->printSuperBlock();

	int inode=0;
	int inodeIndex;
	ptr->printFreeInodeList();

	for (int i=0 ; i <25 ; i++){
		if (ptr->isFreeInode(i)){
			printf("pass inode %d\n",i);

		}

		else{
			printf("fail inode %d\n",i);
		}
		inode=ptr->allocateInode();

		inodeIndex=inode;
		//printf("allocate the indoe %d ref == %d\n",inodeIndex,inode);
		if (!ptr->isFreeInode(inodeIndex)){
			printf("pass inode %d\n",inodeIndex);
		}
		else{
			printf("fail inode %d\n",inodeIndex);
		}
	}
	for (int i=0 ; i <25 ; i++){
		ptr->freeInode(i);
	}

	ptr->printSuperBlock();
	ptr->printFreeInodeList();
//	ptr->printFList();
	////
	delete(ptr);
}

//testing get and set of inode type
void test16(){
	MyDisk *ptr;
	int blockSize=64;
	int numOfNodes=60;
	ptr=new MyDisk(200,blockSize,numOfNodes,true);
	ptr->printSuperBlock();

	int inode;
	int inodeIndex;
	char* f = "F";
	char* d = "D";
	inode=ptr->allocateInode();//the zero is unwritable
	ptr->setInodeType(inode,f);

	char ans=ptr->getInodeType(inode);
	if (ans == 'F'){
		printf("pass %c\n",ans);
	}
	else{
		printf("fail %c\n",ans);
	}

	inode=ptr->allocateInode();
	ptr->setInodeType(inode,d);
	ans=ptr->getInodeType(inode);
	if (ans == 'D'){
		printf("pass %c\n",ans);
	}
	else{
		printf("fail %c\n",ans);
	}
	ans=ptr->getInodeType(-1);
		if (ans == 'N'){
			printf("pass %c\n",ans);
		}
		else{
			printf("fail %c\n",ans);
		}

	delete(ptr);
}


//testing get and set of hardLinks type
void test17(){
	MyDisk *ptr;
	int blockSize=64;
	int numOfNodes=60;
	ptr=new MyDisk(200,blockSize,numOfNodes,true);
	ptr->printSuperBlock();

	int inode;
	int inodeIndex;
	char* zero = "0";
	char* one = "1";
	inode=ptr->allocateInode();//the zero is unwritable
	inode=ptr->allocateInode();
	ptr->setInodeHlink(inode,zero);

	char ans=ptr->getInodeHlink(inode);
	if (ans == '0'){
		printf("pass %c\n",ans);
	}
	else{
		printf("fail %c\n",ans);
	}

	inode = ptr->allocateInode();
	ptr->setInodeHlink(inode,one);
	ans=ptr->getInodeHlink(inode);
	if (ans == '1'){
		printf("pass %c\n",ans);
	}
	else{
		printf("fail %c\n",ans);
	}
	ans=ptr->getInodeHlink(-1);
		if (ans == 'N'){
			printf("pass %c\n",ans);
		}
		else{
			printf("fail %c\n",ans);
		}

	delete(ptr);
}


//testing get and set of inode size of file
void test18(){
	MyDisk *ptr;
	int blockSize=64;
	int numOfNodes=60;
	ptr=new MyDisk(200,blockSize,numOfNodes,true);
	ptr->printSuperBlock();
	int size = 53;
	int inode;
	inode=ptr->allocateInode();//the zero is unwritable
	inode=ptr->allocateInode();
	ptr->setFileSize(inode,size);

	int ans=ptr->getFileSize(inode);
	if (ans == size){
		printf("pass %d\n",ans);
	}
	else{
		printf("fail %d\n",ans);
	}

	ans=ptr->getFileSize(-1);
		if (ans == -1){
			printf("pass %d\n",ans);
		}
		else{
			printf("fail %d\n",ans);
		}

	delete(ptr);
}


//testing get and set of inode size of file
void test19(){
	MyDisk *ptr;
	int blockSize=64;
	int numOfNodes=60;
	ptr=new MyDisk(200,blockSize,numOfNodes,true);
	ptr->printSuperBlock();

	int inode;
	inode=ptr->allocateInode();//the zero is unwritable
	inode=ptr->allocateInode();
	int tmp=1;
	for (int i=0;i<11;i++){
		tmp=tmp+(i+1);
		ptr->setDataBlock(inode,i,tmp);
	}
	int ans;
	tmp=1;
	for (int i=0;i<11;i++){
		ans=ptr->getDataBlock(inode,i);
		tmp = tmp+(i+1);
		if (tmp == ans){
			printf("pass %d\n",ans);
		}
		else{
		printf("fail %d\n",ans);
		}
	}

	ans=ptr->getDataBlock(-1,0);
	if (ans == -1){
		printf("pass %d\n",ans);
	}
	else{
		printf("fail %d\n",ans);
	}


	delete(ptr);
}


//testing printInode
void test20(){
	MyDisk *ptr;
	int blockSize=64;
	int numOfNodes=60;
	ptr=new MyDisk(200,blockSize,numOfNodes,true);
	ptr->printSuperBlock();

	char* f = "F";
	char* zero = "0";
	int inode;

	inode=ptr->allocateInode();//the zero is unwritable
	inode=ptr->allocateInode();

	ptr->setInodeType(inode,f);
	ptr->setInodeHlink(inode,zero);
	ptr->setFileSize(inode,10);
	int tmp=1;
	for (int i=0;i<11;i++){
		tmp=tmp+(i+1);
		ptr->setDataBlock(inode,i,tmp);
	}
	ptr->printInode(inode);
	delete(ptr);
}


//testing init inode
void test21(){
	MyDisk *ptr;
	int blockSize=64;
	int numOfNodes=60;
	ptr=new MyDisk(200,blockSize,numOfNodes,true);
	ptr->printSuperBlock();


	int inode;
	inode=ptr->allocateInode();//the zero is unwritable
	inode=ptr->allocateInode();
	ptr->printInode(inode);
	delete(ptr);
}

//testing add inode to free list
void test22(){
	MyDisk *ptr;
	int blockSize=64;
	int numOfNodes=60;
	ptr=new MyDisk(200,blockSize,numOfNodes,true);
	ptr->printSuperBlock();
	int inode;
	for (int i=0 ; i < 15 ; i++){
		inode=ptr->allocateInode();
		printf("allocate the indoe %d ref == %d\n",inode,ptr->getInode(inode));
	}
	ptr->printFreeInodeList();
	for (int i=0 ; i < 15 ; i++){
			inode = ptr->addInodeToFreeList(i);
			printf("add to freeList the indoe %d\n",inode);
	}
	ptr->printFreeInodeList();
	delete(ptr);
}

//testing putting block and remove testing size
void test221(){
	MyDisk *ptr;
	int blockSize=64;
	int numOfNodes=60;
	ptr=new MyDisk(200,blockSize,numOfNodes,true);
	ptr->printSuperBlock();
	int numberOfBlocks = ptr->numberOfFreeBlocks();
	int block[10];

	for (int i = 0 ; i < 10 ; i++){
		block[i] = ptr->allocateDataBlock();
	}
	if (numberOfBlocks == ptr->numberOfFreeBlocks() + 10){
		printf("pass allocate blocks and remove from size %d\n",ptr->numberOfFreeBlocks());
	}
	else{
		printf("fail allocate blocks and remove from size %d\n",ptr->numberOfFreeBlocks());
	}
	for (int i = 0 ; i < 10 ; i++){
		ptr->freeDataBlock(block[i]);
	}

	if (numberOfBlocks == ptr->numberOfFreeBlocks()){
		printf("pass B size after free %d\n",ptr->numberOfFreeBlocks());
	}
	else{
		printf("fail B size after free %d\n",ptr->numberOfFreeBlocks());
	}


	delete(ptr);
}

//testing putting block in inode without indorect
void test23(){
	MyDisk *ptr;
	int blockSize=64;
	int numOfNodes=60;
	ptr=new MyDisk(200,blockSize,numOfNodes,true);
	ptr->printSuperBlock();
	int numberOfBlocks = ptr->numberOfFreeBlocks();
	int numberOfInode = ptr->numberOfFreeInodes();
	int block;
	int inode ;
	inode = ptr->allocateInode();

	for (int i = 0 ; i < 10 ; i++){
		block = ptr->allocateDataBlock();
		ptr->setDataBlock(inode , i , block);
	}
	ptr->printInode(inode);

	if (numberOfInode == ptr->numberOfFreeInodes() +1){
		printf("pass allocate and remove from size %d\n",ptr->numberOfFreeInodes());
	}
	else{
		printf("fail allocate and remove from size %d\n",ptr->numberOfFreeInodes());
	}

	if (numberOfBlocks == ptr->numberOfFreeBlocks() + 10){
		printf("pass allocate blocks and remove from size %d\n",ptr->numberOfFreeBlocks());
	}
	else{
		printf("fail allocate blocks and remove from size %d\n",ptr->numberOfFreeBlocks());
	}

	ptr->freeInode(inode);

	if (numberOfInode == ptr->numberOfFreeInodes()){
		printf("pass I size after free %d\n",ptr->numberOfFreeInodes());
	}
	else{
		printf("fail I size after free %d\n",ptr->numberOfFreeInodes());
	}
	if (numberOfBlocks == ptr->numberOfFreeBlocks()){
		printf("pass B size after free %d\n",ptr->numberOfFreeBlocks());
	}
	else{
		printf("fail B size after free %d\n",ptr->numberOfFreeBlocks());
	}


	delete(ptr);
}

// INdirectBlocks
void test233(){
	MyDisk *ptr;
		int blockSize=64;
		int numOfNodes=60;
		ptr=new MyDisk(200,blockSize,numOfNodes,true);
		ptr->printSuperBlock();
		int sizeOfFreeBlock=ptr->numberOfFreeBlocks();
		int block;
		block = ptr->allocateDataBlock();
		ptr->initIndirectBlock(block);
		ptr->printInDirectBlock(block);
		int tmpBlocks[(ptr->SB.blockSize)/4];
		for (int i = 0 ; i < (ptr->SB.blockSize)/4 ;i++){
			tmpBlocks[i]=ptr->allocateDataBlock();
			printf("the next Block is %d\n",tmpBlocks[i]);
			ptr->putNextBlock(block,tmpBlocks[i]);
		}
		ptr->printInDirectBlock(block);
		ptr->deleteInDirectBlock(block);
		if (ptr->numberOfFreeBlocks() == sizeOfFreeBlock){
			printf("pass the indirect delete test %d \n",sizeOfFreeBlock );
		}
		else{
			printf("fail the indirect delete test %d \n",ptr->numberOfFreeBlocks() );
		}
}

//testing putting block in inode with indorect
void test24(){
	MyDisk *ptr;
	int blockSize=64;
	int numOfNodes=60;
	ptr=new MyDisk(200,blockSize,numOfNodes,true);
	ptr->printSuperBlock();
	int numberOfBlocks = ptr->numberOfFreeBlocks();
	int block;
	int inode ;
	inode = ptr->allocateInode();
	int i;
	for (i = 0 ; i < 10 ; i++){
		block = ptr->allocateDataBlock();
		ptr->setDataBlock(inode , i , block);
	}
	int InDirectblock = ptr->allocateDataBlock();
	ptr->setDataBlock(inode , 10 , InDirectblock);
	int addrOfIndirect=InDirectblock*ptr->SB.blockSize;
	for (i = 0 ; i < ptr->SB.blockSize  ; i = i + 4){
		block = ptr->allocateDataBlock();
		ptr->writeInt(block,addrOfIndirect+i);
	}
	if (numberOfBlocks == ptr->numberOfFreeBlocks() + 10 + (i/4) +1){
		printf("pass allocate blocks and remove from size %d\n",ptr->numberOfFreeBlocks());
	}
	else{
		printf("fail allocate blocks and remove from size %d\n",ptr->numberOfFreeBlocks());
	}

	ptr->freeInode(inode);

	if (numberOfBlocks == ptr->numberOfFreeBlocks()){
		printf("pass B size after free %d\n",ptr->numberOfFreeBlocks());
	}
	else{
		printf("fail B size after free %d\n",ptr->numberOfFreeBlocks());
	}


	delete(ptr);
}

// 25 -26 testing nonVolitle info
void test25(){
	MyDisk *ptr;
	int blockSize=64;
	int numOfNodes=60;
	ptr=new MyDisk(200,blockSize,numOfNodes,true);
	ptr->printSuperBlock();
	int numberOfBlocks = ptr->numberOfFreeBlocks();
	int block;
	int inode ;
	inode = ptr->allocateInode();
	int i;
	for (i = 0 ; i < 10 ; i++){
		block = ptr->allocateDataBlock();
		ptr->setDataBlock(inode , i , block);
	}
	int InDirectblock = ptr->allocateDataBlock();
	ptr->setDataBlock(inode , 10 , InDirectblock);
	int addrOfIndirect=InDirectblock*ptr->SB.blockSize;
	for (i = 0 ; i < ptr->SB.blockSize  ; i = i + 4){
		block = ptr->allocateDataBlock();
		ptr->writeInt(block,addrOfIndirect+i);
	}
	ptr->printSuperBlock();
	delete(ptr);
	printf("now please run test 26\n");
}

void test26(){
	printf("shuold pass only afteer test 25\n");
	MyDisk *ptr;
	ptr=new MyDisk(-1,-1,-1,false);
	ptr->printSuperBlock();
	int block;
	int inode ;
	if (147 == ptr->numberOfFreeBlocks() + 27){
		printf("pass allocate blocks and remove from size %d\n",ptr->numberOfFreeBlocks());
	}
	else{
		printf("fail allocate blocks and remove from size %d\n",ptr->numberOfFreeBlocks());
	}

	ptr->freeInode(0);

	if (147 == ptr->numberOfFreeBlocks()){
		printf("pass B size after free %d\n",ptr->numberOfFreeBlocks());
	}
	else{
		printf("fail B size after free %d\n",ptr->numberOfFreeBlocks());
	}
	ptr->printSuperBlock();

	delete(ptr);
}


//testing constructor and getDisk
void test27(){
	FileSystem* FSptr;
	MyDisk* ptr;
	int blockSize=64;
	int numOfNodes=60;
	FSptr = new FileSystem(200,blockSize,numOfNodes);
	ptr = FSptr->getMyDisk();
	int numberOfBlocks = ptr->numberOfFreeBlocks();
	int block;
	int inode ;
	inode = ptr->allocateInode();
	int i;
	for (i = 0 ; i < 10 ; i++){
		block = ptr->allocateDataBlock();
		ptr->setDataBlock(inode , i , block);
	}
	int InDirectblock = ptr->allocateDataBlock();
	ptr->setDataBlock(inode , 10 , InDirectblock);
	int addrOfIndirect=InDirectblock*ptr->SB.blockSize;
	for (i = 0 ; i < ptr->SB.blockSize  ; i = i + 4){
		block = ptr->allocateDataBlock();
		ptr->writeInt(block,addrOfIndirect+i);
	}
	if (numberOfBlocks == ptr->numberOfFreeBlocks() + 10 + (i/4) +1){
		printf("pass allocate blocks and remove from size %d\n",ptr->numberOfFreeBlocks());
	}
	else{
		printf("fail allocate blocks and remove from size %d\n",ptr->numberOfFreeBlocks());
	}

	ptr->freeInode(inode);

	if (numberOfBlocks == ptr->numberOfFreeBlocks()){
		printf("pass B size after free %d\n",ptr->numberOfFreeBlocks());
	}
	else{
		printf("fail B size after free %d\n",ptr->numberOfFreeBlocks());
	}


	delete(FSptr);
}

//testing constructor nonVolitle and createFile , createDir and print
void test28(){
	FileSystem* FSptr;
	MyDisk* ptr;
	FSptr = new FileSystem();
	ptr = FSptr->getMyDisk();
	int directory = FSptr->createDir();
	int regularFile = FSptr->createFile('F');
	int linkFile = FSptr->createFile('L');
	FSptr->printFile(regularFile);
	FSptr->printFile(directory);
	FSptr->printFile(linkFile);
	FSptr->d_delete(directory);
	FSptr->f_delete(regularFile);
	FSptr->f_delete(linkFile);
	ptr->printSuperBlock();
	delete(FSptr);
}


//testing f_write f_read direct only
void test29(){
	FileSystem* FSptr;
	MyDisk* ptr;
	FSptr = new FileSystem();
	ptr = FSptr->getMyDisk();
	int i;
	int regularFile = FSptr->createFile('F');
	char * inf = "123456789123456789  end";
	int len=strlen(inf);
	char * info =(char*)malloc(len*7);
	for ( i=0; i < 7 ; i++){
		strncpy( info+(i*len), inf, len );
	}
	printf("check info  = %s\n",info);

	int nBytes=strlen(info);
	char * getInfo=(char*)malloc(nBytes);

	FSptr->f_write(regularFile,info,0,nBytes);
	FSptr->f_read(regularFile,getInfo,0,nBytes);
	if (strncmp( info, getInfo, nBytes ) == 0){
		printf("pass read write file direct %s\n",getInfo);
	}
	else{
		printf("fail read write file direct %s\n",getInfo);
	}
	FSptr->printFile(regularFile);
	FSptr->f_delete(regularFile);

	ptr->printSuperBlock();

	delete(FSptr);
}

//testing f_write f_read Indirect only ,writing after wiriting

void test31(){
	FileSystem* FSptr;
	MyDisk* ptr;
	FSptr = new FileSystem();
	ptr = FSptr->getMyDisk();
	int i;
	int regularFile = FSptr->createFile('F');
	char * inf = "12345678912345\n";
	int len=strlen(inf);
	printf("len = %d\n",len);
	char * info =(char*)malloc(len*65);
	for ( i=0; i < 65 ; i++){
		strncpy( info+(i*len), inf, len );
	}
	int nBytes=strlen(info);
	char * getInfo=(char*)malloc(nBytes);
	printf("nBytes = %d\n",nBytes);
	FSptr->f_write(regularFile,info,0,nBytes);
	FSptr->f_read(regularFile,getInfo,0,nBytes);
	if (strncmp( info, getInfo, nBytes ) == 0){
		printf("pass read write file INdirect %d\n",strlen(getInfo));
	}
	else{
		printf("fail read write file INdirect %d\n",strlen(getInfo));
	}

	int ref = 1234;//ref in the file
	inf = "GAL_SAGIE\n";
	 len=strlen(inf);
	printf("len = %d\n",len);
	info =(char*)malloc(len*5);
	for ( i=0; i < 5 ; i++){
		strncpy( info+(i*len), inf, len );
	}
	nBytes=strlen(info);
	char * getInfo2=(char*)malloc(nBytes);
	printf("nBytes = %d\n",nBytes);
	printf("write second time %d\n",FSptr->f_write(regularFile,info,ref,nBytes));
	FSptr->f_read(regularFile,getInfo2,ref,nBytes);
	if (strncmp( info, getInfo2, nBytes ) == 0){
		printf("pass read write file INdirect after wirting/read %d\n",strlen(getInfo2));
	}
	else{
		printf("fail read write file INdirect after wirting/read %d\n",strlen(getInfo2));
	}


	FSptr->printFile(regularFile);
	FSptr->f_delete(regularFile);

	ptr->printSuperBlock();

	delete(FSptr);
}


//testing f_write f_read Indirect only ,1650 bytes of string
void test30(){
	FileSystem* FSptr;
	MyDisk* ptr;
	int blockSize=64;
	int numOfNodes=60;
	FSptr = new FileSystem(200,blockSize,numOfNodes);
	ptr = FSptr->getMyDisk();
	int i;
	int regularFile = FSptr->createFile('F');
	char * inf = "12345678912345\n";
	int len=strlen(inf);
	printf("len = %d\n",len);
	char * info =(char*)malloc(len*110);
	for ( i=0; i < 110 ; i++){
		strncpy( info+(i*len), inf, len );
	}
	int nBytes=strlen(info);
	char * getInfo=(char*)malloc(nBytes);
	printf("nBytes = %d\n",nBytes);
	FSptr->f_write(regularFile,info,0,nBytes);
	FSptr->f_read(regularFile,getInfo,0,nBytes);
	if (strncmp( info, getInfo, nBytes ) == 0){
		printf("pass read write file INdirect %d\n",strlen(getInfo));
	}
	else{
		printf("fail read write file INdirect %d\n",strlen(getInfo));
	}
	FSptr->printFile(regularFile);
	FSptr->f_delete(regularFile);
	ptr->printSuperBlock();

	delete(FSptr);
}



//testing wrriting to the end of a file directly and print it
void test32(){
	FileSystem* FSptr;
	MyDisk* ptr;
	FSptr = new FileSystem();
	ptr = FSptr->getMyDisk();
	int regularFile = FSptr->createFile('F');
	char * inf = "\nGAL_SAGIE\n";
	int len=strlen(inf);
	FSptr->f_write(regularFile,inf,1234,len);


	FSptr->printFile(regularFile);
	FSptr->f_delete(regularFile);

	ptr->printSuperBlock();

	delete(FSptr);
}

void test33(){
	pair<int,char*> p1;
	p1.first= 1;
	p1.second="str";
	printf("<%s,%d>\n",p1.second,p1.first);
}

//testing listToString and printList
void test34(){
	FileSystem* FSptr;
	MyDisk* ptr;
	FSptr = new FileSystem();
	ptr = FSptr->getMyDisk();

	list<pair<int , char*> >* mylist = new list<pair<int , char*> >();


	pair<int,char* > p1;
	pair<int,char* > p2;
	pair<int,char* > p3;
	char * tmp1 =(char*)malloc(13);
	char * tmp2 =(char*)malloc(13);
	char * tmp3 =(char*)malloc(13);
	strncpy(tmp1 ,"games",5);
	strncpy(tmp2 ,"check2",6);
	strncpy(tmp3 ,"check3",6);
	FSptr->makeValidName(tmp1);
	FSptr->makeValidName(tmp2);
	FSptr->makeValidName(tmp3);
	p1.first=1;
	p1.second=tmp1;
	p2.first=23;
	p2.second=tmp2;
	p3.first=34;
	p3.second=tmp3;

	mylist->push_back(p1);
	mylist->push_back(p2);
	mylist->push_back(p3);
	char* ans =(char*)malloc(16*3);
	FSptr->listToString(mylist,ans);
//	FSptr->printDirectoryList(mylist);
	ptr->printSuperBlock();

	free(tmp1);
	free(tmp2);
	free(tmp3);
	delete(mylist);
	delete(FSptr);
}


//testing listToString and printList
void test35(){
	list<pair<int , char*> >* mylist=new list<pair<int , char*> >();
	list<pair<int , char*> >* mylist2 = new list<pair<int , char*> >();

	FileSystem* FSptr;
	MyDisk* ptr;
	FSptr = new FileSystem();
	ptr = FSptr->getMyDisk();




	pair<int,char* > p1;
	pair<int,char* > p2;
	pair<int,char* > p3;
	pair<int,char* > p4;
	char * tmp1 =(char*)malloc(13);
	char * tmp2 =(char*)malloc(13);
	char * tmp3 =(char*)malloc(13);
	char * tmp4 =(char*)malloc(13);
	strncpy(tmp1 ,"games",5);
	strncpy(tmp2 ,"check2",6);
	strncpy(tmp3 ,"check3",6);
	strncpy(tmp4 ,"check4",6);
	FSptr->makeValidName(tmp1);
	FSptr->makeValidName(tmp2);
	FSptr->makeValidName(tmp3);
	printf("tmp3=[%s]\n",tmp3);
	FSptr->makeValidName(tmp4);
	p1.first=1;
	p1.second=tmp1;
	p2.first=23;
	p2.second=tmp2;
	p3.first=34;
	p3.second=tmp3;
	p4.first=45;
	p4.second=tmp4;

	mylist->push_back(p1);
	mylist->push_back(p2);
	mylist->push_back(p3);
	mylist->push_back(p4);
	char* ans =(char*)malloc(16*4);
	FSptr->listToString(mylist,ans);
	printf("ans = %s\n",ans);
//	FSptr->printDirectoryList(mylist);



	FSptr->stringToList(mylist2 ,ans);
	printf("ans = %s\n",ans);
	printf("ans.size = %d\n",strlen(ans));
//	FSptr->printDirectoryList(mylist2);
	ptr->printSuperBlock();

	free(tmp1);
	free(tmp2);
	free(tmp3);
	delete(FSptr);
}
//test valid name
void test36(){
	FileSystem* FSptr;
	MyDisk* ptr;
	FSptr = new FileSystem();
	ptr = FSptr->getMyDisk();
	char * name = (char*)malloc(13);
	strncpy(name,"games",5);
	FSptr->makeValidName(name);
	printf("[%s]\n",name);

	delete(FSptr);
}

void test37(){
	FileSystem* FSptr;
	MyDisk* ptr;
	FSptr = new FileSystem();
	ptr = FSptr->getMyDisk();
	list<pair<int , char*> >* mylist = new list<pair<int , char*> >();
	pair<int,char* > p1;
	pair<int,char* > p2;
	pair<int,char* > p3;
	char * tmp1 =(char*)malloc(13);
	char * tmp2 =(char*)malloc(13);
	char * tmp3 =(char*)malloc(13);
	char * equal= (char*)malloc(13);
	char * notEqual= (char*)malloc(13);
	strncpy(equal ,"check2   ",12);
	strncpy(notEqual ,"gsames",13);
	strncpy(tmp1 ,"games",5);
	strncpy(tmp2 ,"check2",6);
	strncpy(tmp3 ,"check3",6);
	FSptr->makeValidName(tmp1);
	FSptr->makeValidName(tmp2);
	FSptr->makeValidName(tmp3);
	p1.first=1;
	p1.second=tmp1;
	p2.first=23;
	p2.second=tmp2;
	p3.first=34;
	p3.second=tmp3;
	mylist->push_back(p1);
	mylist->push_back(p2);
	mylist->push_back(p3);
	char* ans =(char*)malloc(16*3);
	FSptr->listToString(mylist,ans);
//	FSptr->printDirectoryList(mylist);
	if (FSptr->getInodeNumber( equal,mylist) == 23){
		printf("pass getInodeNumber %d\n",FSptr->getInodeNumber( equal,mylist));
	}
	else
		printf("fail getInodeNumber %d\n",FSptr->getInodeNumber( equal,mylist));

	if (FSptr->getInodeNumber( notEqual,mylist) == -2){
			printf("pass getInodeNumber notEqual %d\n",FSptr->getInodeNumber( notEqual,mylist));
		}
		else
			printf("fail getInodeNumber notEqual %d\n",FSptr->getInodeNumber( notEqual,mylist));
	ptr->printSuperBlock();


		free(tmp1);
		free(tmp2);
		free(tmp3);
		delete(mylist);
		delete(FSptr);
}

//testing d_write and d_read printing the content of the directory as a file
void test38(){
	FileSystem* FSptr;
	MyDisk* ptr;
	FSptr = new FileSystem();
	ptr = FSptr->getMyDisk();
	list<pair<int , char*> >* mylist = new list<pair<int , char*> >();
	pair<int,char* > p1;
	pair<int,char* > p2;
	pair<int,char* > p3;
	char * tmp1 =(char*)malloc(13);
	char * tmp2 =(char*)malloc(13);
	char * tmp3 =(char*)malloc(13);
	char * equal= (char*)malloc(13);
	char * notEqual= (char*)malloc(13);

	int rootNode=FSptr->createDir();
	int inode2=FSptr->createDir();

	printf("debug1\n");

	strncpy(tmp1 ,"games",5);
	strncpy(tmp2 ,"check2",6);
	strncpy(tmp3 ,"check3",6);
	FSptr->makeValidName(tmp1);
	FSptr->makeValidName(tmp2);
	FSptr->makeValidName(tmp3);
	p1.first=1;
	p1.second=tmp1;
	p2.first=23;
	p2.second=tmp2;
	p3.first=34;
	p3.second=tmp3;
	mylist->push_back(p1);
	mylist->push_back(p2);
	mylist->push_back(p3);
	char* ans =(char*)malloc(16*3);
	FSptr->listToString(mylist,ans);
	printf("ans = \n%s\n",ans);

	FSptr->d_write(rootNode,mylist);
	FSptr->d_write(inode2,mylist);
	FSptr->printFile(rootNode);
	FSptr->printFile(inode2);

	//**testing reading*/
	list<pair<int , char*> >* tmplist2;

	tmplist2 = FSptr->d_read(rootNode);
	printf("the size of the list return from read %d\n",tmplist2->size());
	char * inode2str = (char*)malloc(tmplist2->size()*16);
	FSptr->listToString(tmplist2 , inode2str);
	printf("inode2str = \n%s\n",inode2str);


//	FSptr->printDirectoryList(mylist);



	FSptr->f_delete(rootNode);
	FSptr->f_delete(inode2);
	ptr->printSuperBlock();


		free(tmp1);
		free(tmp2);
		free(tmp3);
		delete(mylist);
		delete(FSptr);
}


//testing d_write and d_read and d_delete
void test39(){
	FileSystem* FSptr;
	MyDisk* ptr;
	FSptr = new FileSystem();
	ptr = FSptr->getMyDisk();
	list<pair<int , char*> >* mylist = new list<pair<int , char*> >();
	pair<int,char* > p1;
	pair<int,char* > p2;
	pair<int,char* > p3;
	char * tmp1 =(char*)malloc(13);
	char * tmp2 =(char*)malloc(13);
	char * tmp3 =(char*)malloc(13);
	int rootNode=FSptr->createDir();

	strncpy(tmp1 ,"games",5);
	strncpy(tmp2 ,"check2",6);
	strncpy(tmp3 ,"check3",6);
	FSptr->makeValidName(tmp1);
	FSptr->makeValidName(tmp2);
	FSptr->makeValidName(tmp3);
	p1.first=1;
	p1.second=tmp1;
	p2.first=23;
	p2.second=tmp2;
	p3.first=34;
	p3.second=tmp3;
	mylist->push_back(p1);
	mylist->push_back(p2);
	mylist->push_back(p3);
	FSptr->d_write(rootNode,mylist);
	FSptr->printFile(rootNode);
	if (-1 == FSptr->d_delete(rootNode)){
		printf("pass not delete notempty dir\n");
	}
	else{
		printf("fail not delete notempty dir %d\n",FSptr->d_delete(rootNode));
	}

	char * empty=(char*)malloc(21);
	strncat(empty,"11111111111111111111",20);
	FSptr->d_write(rootNode,NULL);

	printf("delet inode = %d \n",FSptr->disk->deleteInode(rootNode));
	FSptr->printFile(rootNode);
//	FSptr->f_write(rootNode,empty,0,21);
	if (rootNode == FSptr->d_delete(rootNode)){
			printf("pass delete rootNode dir %d\n",rootNode);
		}
		else{
			printf("fail  delete rootNode dir %d\n",FSptr->d_delete(rootNode));
	}






	FSptr->f_delete(rootNode);

	ptr->printSuperBlock();


		free(tmp1);
		free(tmp2);
		free(tmp3);
		delete(mylist);
		delete(FSptr);
}
/**
 * numberOfInodes=120;
static int diskSize= 200;
static int blockSize=64;
 */
//testing tokenizer and root
void test40(){
	SystemCall *sys;
	sys = new SystemCall(diskSize ,blockSize ,numberOfInodes);
	///
	vector<string> results;
	sys->pathTokenizer("/lib1/lib2/lib3", results);
	printf("results size %d\n",results.size());
	int i = 0;
	for (i = 0; i < results.size() ; i++){
		cout<<results.at(i)<<endl;
	}

	///
	sys->fileSys->disk->printSuperBlock();
	delete(sys);
}

//testing d-write and d_read
/*
void test401(){

	SystemCall *sys;
	sys = new SystemCall();
	sys->fileSys->printFile(0);
	///
	list<pair<int , char*> >* mylist = new list<pair<int , char*> >();
	pair<int,char* > p1;
	pair<int,char* > p2;
	pair<int,char* > p3;
	char * tmp1 =(char*)malloc(13);
	char * tmp2 =(char*)malloc(13);
	char * tmp3 =(char*)malloc(13);

	strncpy(tmp1 ,"games",5);
	strncpy(tmp2 ,"check2",6);
	strncpy(tmp3 ,"check3",6);
	sys->fileSys->makeValidName(tmp1);
	sys->fileSys->makeValidName(tmp2);
	sys->fileSys->makeValidName(tmp3);
	p1.first=1;
	p1.second=tmp1;
	p2.first=23;
	p2.second=tmp2;
	p3.first=34;
	p3.second=tmp3;
	mylist->push_back(p1);
	mylist->push_back(p2);
	mylist->push_back(p3);

	sys->fileSys->d_write(0,mylist);
	sys->fileSys->d_write(0,mylist);
	sys->fileSys->printFile(0);
	sys->fileSys->disk->deleteInode(0);

	sys->fileSys->printFile(0);
	sys->fileSys->disk->printSuperBlock();
	delete(sys);
}

*/

//testing chaeckAndSetDir and delete inode from dir
void test41(){

	SystemCall *sys;
	sys = new SystemCall();
	sys->fileSys->printFile(0);
	///

	string path1 ="/root/lib2";
	string path2 ="/root/lib3";
	string path3 ="/root/lib4";
	int inode1 = sys->checkAndSetDir(path1,'D');
	int inode2 = sys->checkAndSetDir(path2,'D');
	int inode3 = sys->checkAndSetDir(path3,'D');


	///
	sys->fileSys->printFile(0);
	printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`\n");
	sys->deleteInodeFromDir(0,inode1);
	printf("now delete lib2\n");
	sys->fileSys->printFile(0);
	sys->deleteInodeFromDir(0,inode2);
	sys->deleteInodeFromDir(0,inode3);
	printf("now delete all\n");
	sys->fileSys->disk->freeInode(inode1);
	sys->fileSys->disk->freeInode(inode2);
	sys->fileSys->disk->freeInode(inode3);
	sys->fileSys->printFile(0);
	sys->fileSys->disk->printSuperBlock();
	delete(sys);
}

//testing newFTE
void test42(){

	SystemCall *sys;
	sys = new SystemCall();
	int i;
	for (i = 0; i< 120 ; i++){
		sys->newFTE(i,true);
	}
	for (i = 0; i< 120 ; i++){
		if (sys->fileTable.find(i)->second.inode == i){
			printf("pass %d\n",i);
		}
		else{
			printf("fail %d\n",i);
		}
	}
	if (sys->newFTE(i,true) == -1){
		printf("pass \n");
	}
	else{
		printf("fail \n");
	}
	sys->fileSys->disk->printSuperBlock();
	delete(sys);
}


//testing makeFilw
void test43(){

	SystemCall *sys;
	sys = new SystemCall();
	int fd1 = sys->MakeDir("root/games");
	int fd2 = sys->MakeFile("root/games/file",'F',true);

	int inode2 = sys->fileTable.find(fd2)->second.inode;

	string hello="hello world";
	sys->fileTable.find(fd2)->second.location = sys->fileSys->f_write(inode2,
			(char *)hello.c_str(),0,11);

	int x = sys->fileTable.find(fd2)->second.location;

	sys->fileSys->f_write(inode2,
				(char *)hello.c_str(),x,11);

	string h2="hello worldhello world";
	char * reading = (char*)malloc(22);
	sys->fileSys->f_read(inode2,reading,0,22);

	if (strncmp((char*)h2.c_str(),reading, 22) == 0){
		printf("pass \n");
	}
	else{
		printf("fail \n");
	}

	sys->fileSys->printFile(sys->fileTable.find(fd1)->second.inode);
	sys->fileSys->printFile(sys->fileTable.find(fd2)->second.inode);

	sys->fileSys->disk->deleteInode(0);
	sys->fileSys->disk->printSuperBlock();
	delete(sys);
}

//testing makeFilw and RmFile
void test44(){

	SystemCall *sys;
	sys = new SystemCall();
	int fd1 = sys->MakeDir("root/games");
	int fd2 = sys->MakeFile("root/games/file",'F',true);

	int inode2 = sys->fileTable.find(fd2)->second.inode;

	string hello="hello world";
	sys->fileTable.find(fd2)->second.location = sys->fileSys->f_write(inode2,
			(char *)hello.c_str(),0,11);

	int x = sys->fileTable.find(fd2)->second.location;

	sys->fileSys->f_write(inode2,
				(char *)hello.c_str(),x,11);

	string h2="hello worldhello world";
	char * reading = (char*)malloc(22);
	sys->fileSys->f_read(inode2,reading,0,22);

	if (strncmp((char*)h2.c_str(),reading, 22) == 0){
		printf("pass \n");
	}
	else{
		printf("fail \n");
	}
	sys->fileSys->printFile(sys->fileTable.find(fd1)->second.inode);
	sys->fileSys->printFile(sys->fileTable.find(fd2)->second.inode);
	sys->RmFile("root/games/file");
	sys->RmFile("root/games");
	vector<string> results;
	sys->pathTokenizer("root/games/file",results);
	if (sys->getCurrentDir("root/games/file/",results) == -1){
		printf("Pass rmFile ::shuold print error above\n");
	}
	else{
		printf("fail rmFile return %d\n",sys->getCurrentDir("root/games/file",results));
	}
	if (sys->fileSys->disk->numberOfFreeInodes() == 59){
		printf("pass test of free inode\n");
	}
	else{
		printf("fail test of free inode\n");
	}

	sys->fileSys->disk->deleteInode(0);
	sys->fileSys->disk->printSuperBlock();
	delete(sys);
}

//testing makeFilw and RmDir
void test45(){

	SystemCall *sys;
	sys = new SystemCall();
	int fd1 = sys->MakeDir("root/games");
	int fd2 = sys->MakeFile("root/games/file",'F',true);
	int inode1 = sys->fileTable.find(fd1)->second.inode;
	int inode2 = sys->fileTable.find(fd2)->second.inode;
	string hello="hello world";
	sys->fileTable.find(fd2)->second.location = sys->fileSys->f_write(inode2,
			(char *)hello.c_str(),0,11);
	int x = sys->fileTable.find(fd2)->second.location;
	sys->fileSys->f_write(inode2,
				(char *)hello.c_str(),x,11);
	string h2="hello worldhello world";
	char * reading = (char*)malloc(22);
	sys->fileSys->f_read(inode2,reading,0,22);
	if (strncmp((char*)h2.c_str(),reading, 22) == 0){
		printf("pass \n");
	}
	else{
		printf("fail \n");
	}
	sys->fileSys->printFile(sys->fileTable.find(fd1)->second.inode);
	sys->fileSys->printFile(sys->fileTable.find(fd2)->second.inode);

	if (sys->RmDir("root/games") == -1){
		printf("Pass rmDir ::shuold print error above\n");
	}
	else{
		printf("fail rmDir return \n");
	}
	sys->RmFile("root/games/file");
	int rmDir = sys->RmDir("root/games");
	if (rmDir == inode1){
		printf("Pass rmDir \n");
	}
	else{
		printf("fail  rmDir %d\n",rmDir);
	}

	if (sys->fileSys->disk->numberOfFreeInodes() == 59){
		printf("pass test of free inode\n");
	}
	else{
		printf("fail test of free inode\n");
	}

	sys->fileSys->disk->deleteInode(0);
	sys->fileSys->disk->printSuperBlock();
	delete(sys);
}

//testing makeFilw and RmDir
void test46(){

	SystemCall *sys;
	sys = new SystemCall();
	int fd1 = sys->MakeDir("root/games");
	int fd2 = sys->MakeFile("root/games/file",'F',true);
	int fd3 = sys->MakeFile("root/file2",'F',true);
	int inode1 = sys->fileTable.find(fd1)->second.inode;
	int inode2 = sys->fileTable.find(fd2)->second.inode;
	int inode3 = sys->fileTable.find(fd2)->second.inode;
	string hello="hello world";
	sys->fileTable.find(fd2)->second.location = sys->fileSys->f_write(inode2,
			(char *)hello.c_str(),0,11);
	int x = sys->fileTable.find(fd2)->second.location;
	sys->fileSys->f_write(inode2,
				(char *)hello.c_str(),x,11);
	string h2="hello worldhello world";
	char * reading = (char*)malloc(22);
	sys->fileSys->f_read(inode2,reading,0,22);
	if (strncmp((char*)h2.c_str(),reading, 22) == 0){
		printf("pass \n");
	}
	else{
		printf("fail \n");
	}
	sys->fileSys->printFile(sys->fileTable.find(fd1)->second.inode);
	sys->fileSys->printFile(sys->fileTable.find(fd2)->second.inode);
	sys->printDir("root/games");

	if (sys->RmDir("root/games") == -1){
		printf("Pass rmDir ::shuold print error above\n");
	}
	else{
		printf("fail rmDir return \n");
	}
	sys->RmFile("root/games/file");
	int rmDir = sys->RmDir("root/games");
	if (rmDir == inode1){
		printf("Pass rmDir \n");
	}
	else{
		printf("fail  rmDir %d\n",rmDir);
	}


	sys->RmFile("root/file2");
	if (sys->fileSys->disk->numberOfFreeInodes() == 59){
		printf("pass test of free inode\n");
	}
	else{
		printf("fail test of free inode\n");
	}

	sys->fileSys->disk->deleteInode(0);
	sys->fileSys->disk->printSuperBlock();
	delete(sys);
}


//testing ls
void test47(){

	SystemCall *sys;
	sys = new SystemCall();
	int fd1 = sys->MakeDir("root/games");
	int fd2 = sys->MakeFile("root/games/file",'F',true);
	int fd3 = sys->MakeFile("root/file2",'F',true);
	int fd4 = sys->MakeDir("root/lib2");
	int fd5 = sys->MakeDir("root/lib3");
	int inode1 = sys->fileTable.find(fd1)->second.inode;
	int inode2 = sys->fileTable.find(fd2)->second.inode;
	int inode3 = sys->fileTable.find(fd3)->second.inode;
	int inode4 = sys->fileTable.find(fd4)->second.inode;
	int inode5 = sys->fileTable.find(fd5)->second.inode;
	sys->fileSys->printFile(0);
	sys->fileSys->printFile(inode1);
	sys->fileSys->printFile(inode2);
	sys->fileSys->printFile(inode3);
	sys->fileSys->printFile(inode4);
	sys->fileSys->printFile(inode5);

	char* ans =(char *)malloc(13*4);
	sys->ls("root/games",ans);
	string comp= "games\nfile2\nlib2\nlib3\n";
	if (strncmp(ans,(char*)comp.c_str(),22) == 0){
		printf("pass ls %s\n",ans);
	}else{
		printf("fail ls %s\n",ans);
	}
	printf("remove %d\n",sys->RmFile("root/games/file"));
	printf("remove %d\n",sys->RmDir("root/games"));
	printf("remove %d\n",sys->RmFile("root/file2"));
	printf("remove %d\n",sys->RmFile("root/lib2"));
	printf("remove %d\n",sys->RmFile("root/lib3"));
	if (sys->fileSys->disk->numberOfFreeInodes() == 59){
		printf("pass test of free inode\n");
	}
	else{
		printf("fail test of free inode\n");
	}

	sys->fileSys->disk->deleteInode(0);
	sys->fileSys->disk->printSuperBlock();
	delete(sys);
}

//testing Open Close
void test48(){

	SystemCall *sys;
	sys = new SystemCall();
	int fd1 = sys->MakeDir("root/games");
	int fd2 = sys->MakeFile("root/games/file",'F',true);
	int fd3 = sys->MakeFile("root/file2",'F',true);
	int fd4 = sys->createSoftLink("root/shourt","root/games/file");
	int inode1 = sys->fileTable.find(fd1)->second.inode;
	int inode2 = sys->fileTable.find(fd2)->second.inode;
	int inode3 = sys->fileTable.find(fd3)->second.inode;
	int inode4 = sys->fileTable.find(fd4)->second.inode;
	sys->fileSys->printFile(0);
	sys->fileSys->printFile(inode1);
	sys->fileSys->printFile(inode2);
	sys->fileSys->printFile(inode3);
	sys->fileSys->printFile(inode4);

	int fd5 = sys->Open("root/games/file",true);
	if (sys->fileTable.find(fd5)->second.inode == inode2){
		printf("pass Open %d\n",inode2);
	}
	else{
		printf("fail Open %d\n",sys->fileTable.find(fd5)->second.inode);
	}
	if (inode4 == inode2){
		printf("pass createsoftLink %d\n",inode4);
	}
	else{
		printf("fail createsoftLink %d\n",inode4);
	}
	sys->Close(fd1);
	sys->Close(fd2);
	sys->Close(fd3);
	sys->Close(fd4);
	sys->Close(fd5);
	if (0 == sys->fileTableSize()){
			printf("pass Close %d\n",sys->fileTableSize());
		}
		else{
			printf("fail Close %d\n",sys->fileTableSize());
		}
	printf("remove %d\n",sys->RmFile("root/games/file"));
	printf("remove %d\n",sys->RmDir("root/games"));
	printf("remove %d\n",sys->RmFile("root/file2"));
	printf("remove %d\n",sys->RmFile("root/shourt"));
	if (sys->fileSys->disk->numberOfFreeInodes() == numberOfInodes-1){
		printf("pass test of free inode\n");
	}
	else{
		printf("fail test of free inode\n");
	}

	sys->fileSys->disk->deleteInode(0);
	sys->fileSys->disk->printSuperBlock();
	delete(sys);
}


//testing Open Close read and write
void test49(){

	SystemCall *sys;
	sys = new SystemCall();
	int fd1 = sys->MakeDir("root/games");
	int fd2 = sys->MakeFile("root/games/file",'F',true);

	int inode1 = sys->fileTable.find(fd1)->second.inode;
	int inode2 = sys->fileTable.find(fd2)->second.inode;

	sys->fileSys->printFile(0);
	sys->fileSys->printFile(inode1);
	sys->fileSys->printFile(inode2);


	int fd5 = sys->Open("root/games/file",true);
	if (sys->fileTable.find(fd5)->second.inode == inode2){
		printf("pass Open %d\n",inode2);
	}
	else{
		printf("fail Open %d\n",sys->fileTable.find(fd5)->second.inode);
	}

	string myText="Gal i hope you see this your name is all over this job";
	int txtLen=myText.size();
	sys->Write(fd2,txtLen,(char*)myText.c_str());
	char* ans = (char*)malloc(txtLen);
	sys->Seek(fd2,0);
	sys->Read(fd2,txtLen,ans);
	if (strncmp(ans ,(char*)myText.c_str(),txtLen-1) == 0){
		printf("pass read/write \n[%s] \n",ans);
	}
	else{
		printf("fail read/write \n[%s] \n",ans);
	}
	free(ans);
	sys->Close(fd1);
	sys->Close(fd2);
	sys->Close(fd5);
	if (0 == sys->fileTableSize()){
			printf("pass Close %d\n",sys->fileTableSize());
		}
		else{
			printf("fail Close %d\n",sys->fileTableSize());
	}
	if (sys->isDir("root/games") && !sys->isDir("root/games/file")){
		printf("pass isDir \n");
	}
	else{
		printf("fail isDir \n");
	}
	printf("remove %d\n",sys->RmFile("root/games/file"));
	printf("remove %d\n",sys->RmDir("root/games"));

	if (sys->fileSys->disk->numberOfFreeInodes() == numberOfInodes-1){
		printf("pass test of free inode\n");
	}
	else{
		printf("fail test of free inode\n");
	}

	sys->fileSys->disk->deleteInode(0);
	sys->fileSys->disk->printSuperBlock();
	delete(sys);
}


//testing makeHlink
void test50(){

	SystemCall *sys;
	sys = new SystemCall();
	sys->fileSys->disk->printFreeInodeList();
	int fd1 = sys->MakeDir("root/games");
	int fd2 = sys->MakeFile("root/games/file",'F',true);
	sys->MakeHLink("root/games/file","root/hfile");
	int fd3 = sys->Open("root/hfile",true);
	int inode1 = sys->fileTable.find(fd1)->second.inode;
	int inode2 = sys->fileTable.find(fd2)->second.inode;
	int inode3 = sys->getInodeFromPath("root/hfile");

	if (inode3 = inode2){
		printf("pass hlink test of copy %d\n",inode3);
	}
	else{
		printf("fail hlink test of copy %d\n",inode3);
	}

	sys->fileSys->printFile(0);
	sys->fileSys->printFile(inode1);
	sys->fileSys->printFile(inode2);
	sys->fileSys->printFile(inode3);



	sys->Close(fd1);
	sys->Close(fd2);
	sys->Close(fd3);
	if (0 == sys->fileTableSize()){
			printf("pass Close %d\n",sys->fileTableSize());
		}
		else{
			printf("fail Close %d\n",sys->fileTableSize());
	}
	if (sys->isDir("root/games") && !sys->isDir("root/games/file")){
		printf("pass isDir \n");
	}
	else{
		printf("fail isDir \n");
	}
	if (sys->fileSys->disk->getInodeHlink(inode2) == '1'){
		printf("remove %d\n",sys->RmFile("root/games/file"));
		if (sys->fileSys->disk->getInodeHlink(inode2) == '0'){
			printf("pass counter of hard links %c",sys->fileSys->disk->getInodeHlink(inode2));
		}else{
			printf("remove %d\n",sys->RmFile("root/games/file"));
			printf("fail2 counter of hard links %c",sys->fileSys->disk->getInodeHlink(inode2));
		}
	}else{
		printf("fail1 counter of hard links %c",sys->fileSys->disk->getInodeHlink(inode2));
		printf("remove %d\n",sys->RmFile("root/games/file"));
	}



	printf("remove %d\n",sys->RmFile("root/hfile"));
	printf("remove %d\n",sys->RmDir("root/games"));

	if (sys->fileSys->disk->numberOfFreeInodes() == numberOfInodes-1){
		printf("pass test of free inode\n");
	}
	else{
		printf("fail test of free inode\n");
	}

	sys->fileSys->disk->deleteInode(0);
	sys->fileSys->disk->printSuperBlock();
	delete(sys);
}


//testing movefile
void test51(){

	SystemCall *sys;
	sys = new SystemCall();
	int fd1 = sys->MakeDir("root/games");
	int fd2 = sys->MakeFile("root/games/file",'F',true);
	sys->moveFile("root/games/file","root/file");

	int fd3 = sys->Open("root/file",true);
	int inode3 = sys->fdToInode(fd3);
	sys->fileSys->printFile(inode3);



	printf("remove %d\n",sys->RmFile("root/file"));
	printf("remove %d\n",sys->RmDir("root/games"));

	if (sys->fileSys->disk->numberOfFreeInodes() == numberOfInodes-1){
		printf("pass test of free inode\n");
	}
	else{
		printf("fail test of free inode\n");
	}

	sys->fileSys->disk->deleteInode(0);
	sys->fileSys->disk->printSuperBlock();
	delete(sys);
}


int main(){



//	test1();
//	test2();
//	test3();
//	test4();
//	test5();
//	test6();
//	test7();
//	test8();
//	test9();
//	test10();
//	test11();
//	test12();
//	test13();
//	test14();
// 	test15();
//	test16();
//	test17();
//	test18();
//	test19();
//	test20();
//	test21();
//	test22();
//	test221();
//	test23();
//	test233();
//	test24();
//	test25();
//	test26();

	//file System
//	test27();
//	test28();
//	test29();
//	test30();
//	test31();
//	test32();
//	test33();
//	printf("%s\n",itoa (123));
//	test34();
//	test35();
//	test36();
//	test37();
// 	test38();
//	test39();

	//SYSTEM CALL LAYER
//	test39();
	test40();
//	test401();
//	test41();
//	test42();
//	test43();
//	test44();
//	test45();
//	test46();
//	test47();
//	test48();
//	test49();
//	test50();
	test51();

	printf("finish\n");
	return 0;
}